package com.tzy.note.base.thread.proxy;

/**
 * 静态代理对比多线程
 *      多线程就是通过静态代理实现
 *
 * 静态代理模式总结
 *      1.真实对象和代理对象都要实现同一个接口
 *      2.代理对象要代理真实角色
 * 好处
 *      代理对象可以做很多真实对象做不了的事情
 *      真实对象专注做自己的事情
 */
public class StaticProxy {
    public static void main(String[] args) {
        /*
        You you = new You();
        WeddingCompany company = new WeddingCompany(you);
        company.happyMarry();
        */
        //new WeddingCompany(new You()).happyMarry();
        new WeddingCompany(()-> System.out.println("I'm getting married. happy ...")).happyMarry();
        //new Thread(()->System.out.println("l love you")).start();
        /*
        new Thread(()->{
            System.out.println("l love you");
        }).start();
        */
    }

}


interface Marry{
    void happyMarry();
}
//真实角色，你去结婚
class You implements Marry{
    @Override
    public void happyMarry() {
        System.out.println("我要结婚了，超开心...");
    }
}

//代理角色，帮你结婚
class WeddingCompany implements Marry{
    private Marry target;
    public WeddingCompany(Marry marry){
        this.target = marry;
    }
    @Override
    public void happyMarry() {
        before();
        target.happyMarry();
        after();
    }
    private void after() {
        System.out.println("结婚后收拾现场");
    }

    private void before() {
        System.out.println("结婚前布置现场");
    }
}

